'use strict';

module.exports = app => {
    class ClassService extends app.Service {
        constructor(ctx) {
            super(ctx);
        }

        //获取我的班级
        async getClass() {
            const result = await this.ctx.fetch(this.app.urls('getclass'), {
                method: 'get',
                dataType: 'json',
            });
            let data = result.data;

            this.app.logger.info(data);

            if (data.code != 200){
                throw new Error(data.message ? data.message : 'error');
            }

            return data.data;
        }


        //获取我的学生
        async getStudentList(params){
            const result = await this.ctx.fetch(this.app.urls('getstudentlist'), {
                method: 'get',
                dataType: 'json',
                data:{
                    clazzId:params.id,
                }
            });
            let data = result.data;

            this.app.logger.info(data);

            if (data.code != 200){
                throw new Error(data.message ? data.message : 'error');
            }

            return data.data;
        }

        //获取我的学生详情
        async getStudent(params){
            const result = await this.ctx.fetch(this.app.urls('getstudent'), {
                method: 'get',
                dataType: 'json',
                data:{
                    id:params.id,
                }
            });
            let data = result.data;

            this.app.logger.info(data);

            if (data.code != 200){
                throw new Error(data.message ? data.message : 'error');
            }

            return data.data;
        }

    }

    return ClassService;
};
